package car.aistar.service.impl;

import car.aistar.dao.CarRecordDao;
import car.aistar.entity.CarRecord;
import car.aistar.service.CarRecordService;
import car.aistar.util.XrbUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * (CarRecord)表服务实现类
 *
 * @author makejava
 * @since 2020-09-30 20:15:24
 */
@Service("carRecordService")
public class CarRecordServiceImpl implements CarRecordService {
    @Autowired
    private CarRecordDao carRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CarRecord queryById(Long id) {
        return this.carRecordDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CarRecord> queryAllByLimit(int offset, int limit) {
        return this.carRecordDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param carRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CarRecord insert(CarRecord carRecord) {
        this.carRecordDao.insert(carRecord);
        return carRecord;
    }

    /**
     * 修改数据
     *
     * @param carRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CarRecord update(CarRecord carRecord) {
        this.carRecordDao.update(carRecord);
        return this.queryById(carRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.carRecordDao.deleteById(id) > 0;
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<CarRecord> findAll() {
        List<CarRecord> carRecordList = carRecordDao.findAll();
        return carRecordList;
    }

    @Override
    public List<CarRecord> queryAll(CarRecord carRecord) {
        return this.carRecordDao.queryAll(carRecord);
    }

    @Override
    public List<CarRecord> findDate(String date, String date1) {
        Date date3 = new Date();
        Date date2 = new Date();
        try {
            date3 = XrbUtil.StringToDate(date);
            date2 = XrbUtil.StringToDate(date1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        java.sql.Date transDate = new java.sql.Date(date3.getTime());
        java.sql.Date transDate1 = new java.sql.Date(date2.getTime());
        List<CarRecord> carRecords = carRecordDao.findDate(transDate,transDate1);
        return carRecords;
    }

    @Override
    public List<CarRecord> findCarRecord(String brName, String stName, java.sql.Date date, java.sql.Date date1) {
        List<CarRecord> carRecordList = carRecordDao.findCarRecord(brName,stName,date,date1);
        return carRecordList;
    }
}